package main;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.security.Principal;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import javax.jdo.PersistenceManager;
import javax.mail.Multipart;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.PageContext;
import com.sun.xml.internal.stream.Entity.ExternalEntity;
import com.oreilly.servlet.MultipartRequest;

import DBClasses.GameComment;
import DBClasses.GameType;
import DBClasses.NewsLetter;
import DBClasses.User;

@SuppressWarnings("serial")
public class AddComment extends BaseServlet
{
	@SuppressWarnings({ "unused", "rawtypes", "unchecked" })
	@Override
	protected void action(HttpServletRequest req, HttpServletResponse resp)
			throws IOException, ServletException
	{
		try
		{
			GameComment cmnt = new GameComment(req.getParameter("text")
					.toString(), ((UserView) req.getSession().getAttribute(
					"user")).getUser().getLogin(), Long.parseLong(req
					.getParameter("id")));
			PersistenceManager manager = PMF.get().getPersistenceManager();
			manager.makePersistent(cmnt);
			manager.close();
			resp.getWriter().write("success");
		} catch (Exception ex)
		{
			resp.getWriter().write("fail");
		}
	}
}
